package com.yznote.cloudesk.message.controller;

import com.yznote.cloudesk.common.Anno.CollectLogs;
import com.yznote.cloudesk.common.constants.ModuleConstant;
import com.yznote.cloudesk.common.constants.YConstant;
import com.yznote.cloudesk.common.pojo.Friend;
import com.yznote.cloudesk.common.pojo.Message;
import com.yznote.cloudesk.common.pojo.Result;
import com.yznote.cloudesk.common.pojo.User;
import com.yznote.cloudesk.common.utils.YDUtils;
import com.yznote.cloudesk.message.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author : xiaozhoutongxue
 * @date : 2022/10/20 23:21
 */

@Api(tags = "好友系统")
@RestController
@RequestMapping("/friend")
@CollectLogs(moduleName = ModuleConstant.FRIEND_MODULE)
public class FriendController {
    @Autowired
    FriendService friendService;

    @ApiOperation("请求添加好友")
    @GetMapping("/tryInsertFriend")
    public Result tryInsertFriend(@RequestParam Long friendUserId,@RequestParam String notes){
        friendService.tryInsertFriend(friendUserId,notes);
        return Result.success(null);
    }

    @ApiOperation("查询添加好友请求")
    @GetMapping("/queryInsetFriend")
    public Result tryInsetFriend(){
        List<Friend> friends = friendService.queryInsetFriend();
        return Result.build(friends,200, YConstant.SUCCESS);
    }

    @ApiOperation("同意添加好友")
    @GetMapping("/agreedInsetFriend")
    public Result agreedInsetFriend(@RequestParam Long friendUserId){
        friendService.agreedInsetFriend(friendUserId);
        return Result.success(null);
    }

    @ApiOperation("拒绝添加好友")
    @GetMapping("/disagreedInsetFriend")
    public Result disagreedInsetFriend(@RequestParam Long friendUserId){
        friendService.disagreedInsetFriend(friendUserId);
        return Result.success(null);
    }

    @ApiOperation("删除好友")
    @GetMapping("/deleteFriend")
    public Result deleteFriend(@RequestParam Long friendUserId){
        friendService.deleteFriend(friendUserId);
        return Result.success(null);
    }

    @ApiOperation("拉黑好友")
    @GetMapping("/blackoutFriend")
    public Result blackoutFriend(@RequestParam Long friendUserId){
        friendService.BlackoutFriend(friendUserId);
        return Result.success(null);
    }

    @ApiOperation("解除拉黑好友")
    @GetMapping("/unBlackoutFriend")
    public Result unBlackoutFriend(@RequestParam Long friendUserId){
        friendService.unBlackoutFriend(friendUserId);
        return Result.success(null);
    }

    @ApiOperation("返回被该用户拉黑的用户")
    @GetMapping("/getblackoutedFriendList")
    public Result getblackoutedFriendList(){
        List<Friend> friends = friendService.getblackoutedFriendList();
        return Result.build(friends,200,YConstant.SUCCESS);
    }

    @ApiOperation("搜索好友")
    @GetMapping("/searchFriendByName")
    public Result searchFriendByName(@RequestParam String friendUserName){
        List<User> users = friendService.searchFriendByName(friendUserName);
        return Result.build(users,200,YConstant.SUCCESS);
    }

    @ApiOperation("拉取来自某个好友的最新的10条离线消息")
    @GetMapping("/getOfflineMessages")
    public Result getMessage(@RequestParam Long friendUserId,@RequestParam Integer pageSize,@RequestParam Integer pageNum){
        List<Message> messageList = friendService.getOfflineMessages(friendUserId);
        return YDUtils.toPage(pageNum,pageSize,messageList);
    }

}
